<template>
  <div>
    <!-- 返回 -->
    <top-back>
      <template v-slot:back>收货地址</template>
    </top-back>

    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      :disabled-list="disabledList"
      disabled-text="以下地址超出配送范围"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
import TopBack from '@/components/Mine/TopBack'

export default {
  name: 'ChoseAddress',
  components: { TopBack },
  data () {
    return {
      chosenAddressId: '',
      list: [],
      disabledList: [
        {
          id: '3',
          name: '王五',
          tel: '1320000000',
          address: '浙江省杭州市滨江区江南大道 15 号'
        }
      ]
    }
  },
  created () {
    this.list = this.$store.getters.address
    const index = this.list.findIndex(item => item.isDefault)
    if (index !== -1) {
      this.chosenAddressId = this.list[index].id
    }
  },
  methods: {
    onClickLeft () {
      this.$router.go(-1)
    },
    onAdd () {
      this.$router.push({ path: '/addaddress' })
    },
    onEdit (val) {
      this.$router.push({ path: '/setaddress/' + val.id })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
